<template>
  <div class="CateList-header">
    <div class="header-title">
      <div class="back">
        <van-icon
          name="arrow-left"
          color="#fff"
          size="0.34rem"
          @click="onBack"
        />
      </div>
      <div class="title">{{ title }}</div>
      <div class="nullbox"></div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, reactive, onMounted, watch, toRefs } from "vue";
import { useRoute } from "vue-router";

export default defineComponent({
  setup() {
    const route = useRoute();
    const state: { title: any } = reactive({
      title: "",
    });
    onMounted(() => {
      if (route.meta?.title) {
        state.title = route?.meta?.title;
      } else {
        state.title = route?.query?.title;
      }
    });
    watch(route, () => {
      if (route.meta?.title) {
        state.title = route?.meta?.title;
      } else {
        state.title = route?.query?.title;
      }
    });
    return {
      ...toRefs(state),
    };
  },
});
</script>

<style lang="stylus" scoped>
.CateList-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 0.44rem;
  width: 100%;
  display: flex;
  z-index: 100;
  background-color: rgb(189, 0, 255);

  .header-title {
    display: flex;
    height: 100%;
    width: 100%;
    align-items: center;
    text-align: center;

    .back {
      width: 0.5rem;
      height: 0.5rem;
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 100;
    }

    .nullbox {
      width: 0.5rem;
      height: 0.5rem;
    }

    .title {
      flex: 1;
      color: white;
      font-size: 0.17rem;
    }
  }
}
</style>
